/*
 * Copyright (C) Michael Opitz
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
 * USA
 */
#ifndef BLANK_FILETYPE_H
#define BLANK_FILETYPE_H

#include "parse_exception.h"

#include "../model/dom.h"

#include "blank_parser/parser.h"
#include "parser.h"

#include <string>
#include <boost/shared_ptr.hpp>
#include <boost/thread.hpp>
#include <boost/thread/mutex.hpp>

#include "filetype.h"

using namespace std;

/** 
 * \brief This namespaces includes all nertwork related stuff.
 * \author Michael Opitz
 */
namespace network {
	/** 
	 * The blank_filetype is a very simple filetype, which is used by
	 * rs_sockets to communicate with the microcontroller.
	 * \brief This class implements all operations for the blank_filetype
	 */
	class blank_filetype : public network::filetype {
	public:
		blank_filetype();
		virtual ~blank_filetype();
		/** 
		 * \brief parse parses a string into a dom-structure
		 * 
		 * \param msg is the string, which might be received from a 
		 * socket
		 * 
		 * \return a shared_ptr to a dom-structure is returned.
		 */
		virtual boost::shared_ptr<model::dom> parse(
			const string &msg);
		/** 
		 * add_dom is called by a callback-function to add a dom-node to
		 * the internal dom-structure, which is later returned from the
		 * parse-function.
		 * \brief add_dom is called by a callback.
		 * 
		 * \param d is the dom-node which should be added to the
		 * internal dom-structure.
		 */
		void add_dom(boost::shared_ptr<model::dom> d);

		/** 
		 * \brief send converts a dom-structure to the
		 * blank_filetype-format.
		 * 
		 * \param dom is the dom-node which should be converted.
		 * 
		 * \return a string, formatted with the blank_filetype-format,
		 * is returned. This string can be send over a socket.
		 */
		virtual string send(boost::shared_ptr<model::dom> dom);
	private:
		string decode_dom(boost::shared_ptr<model::dom> dom);

		parser_t *_pars;
		boost::shared_ptr<model::dom> _dom;
		boost::mutex _mutex;
	};
}

#endif
